package com.kingint.web.admin.serve.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kingint.mbg.ser.entity.SerReceiveWorkMiddle;
import com.kingint.mbg.ser.mapper.SerReceiveWorkMiddleMapper;
import com.kingint.web.admin.serve.service.SerReceiveWorkMiddleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * <p>
 * 工单总表与接单人中间表（为了首页查询方便做冗余） 服务实现类
 * </p>
 *
 * @author wxh
 * @since 2021-01-08
 */
@Service
public class SerReceiveWorkMiddleServiceImpl extends ServiceImpl<SerReceiveWorkMiddleMapper, SerReceiveWorkMiddle> implements SerReceiveWorkMiddleService {

    @Resource
    private SerReceiveWorkMiddleMapper serReceiveWorkMiddleMapper;

    @Override
    public int insertReceiveWorkInfo(SerReceiveWorkMiddle serReceiveWorkMiddle) {
        serReceiveWorkMiddle.setCreateTime(new Date());
        serReceiveWorkMiddle.setStatus(0);
        int insert = serReceiveWorkMiddleMapper.insert(serReceiveWorkMiddle);
        return insert;
    }

    @Override
    public int updateReceiveWorkInfo(SerReceiveWorkMiddle serReceiveWorkMiddle) {

        QueryWrapper<SerReceiveWorkMiddle> wrapper = new QueryWrapper<>();
        wrapper.eq("work_id",serReceiveWorkMiddle.getWorkId())
                .eq("receive_user_id",serReceiveWorkMiddle.getReceiveUserId());
        int update = serReceiveWorkMiddleMapper.update(serReceiveWorkMiddle, wrapper);
        return update;
    }

    @Override
    public int updateWorkInfo(SerReceiveWorkMiddle serReceiveWorkMiddle) {
        QueryWrapper<SerReceiveWorkMiddle> wrapper = new QueryWrapper<>();
        wrapper.eq("work_id",serReceiveWorkMiddle.getWorkId())
                .eq("status",0);
        int update = serReceiveWorkMiddleMapper.update(serReceiveWorkMiddle, wrapper);
        return update;
    }
}
